import Vue from 'vue'
import Vuex from 'vuex'
import vuexAlong from 'vuex-along'
import storageService from '../utils/storageService'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'',
    userInfo:{},
  },
  mutations: {
    setToken(state,token) {
      storageService.set(storageService.USER_TOKEN,token)
      state.token=token
    },
    setUserInfo(state,userInfo){
      //storageService.set(storageService.USER_INFO,userInfo)
      state.userInfo=userInfo
    }
  },
  actions: {
    setToken(context,token) {
      context.commit('setToken', token)
    },
    setUserInfo(context,userInfo) {
      context.commit('setUserInfo',userInfo)
    }
  },
  modules: {
  },
  //解决刷新后vuex状态问题
  plugins: [vuexAlong()],
})
